Notes on log2csv, a console application that converts
standard waxrec log files to a csv format (all data for all
sensors at 5 minute intervals on one line). There is also
a header line with title for each column (sensor id + unit).

To compile:

Assumes the GNU tool chain in available (gcc + gfortran).
All files needed are in the folder.

  make -f Makefile

This creates executable log2csv.

If you want to tidy up the folder issue the command:

  make -f Makefile clean

All of the source is under GPL. If you change it pass back
the changes to me so that I can incorporate the improvements.

How to use:

Current command line arguments can be found via:
./log2csv -help
command line is:
 [-act {b|s|u|2} ]
   b is standard BuildAX log
   s is short BuildAX log
   u is user units BuildAX log
   2 is BuildAX LRS 2 log
   L scan and list sensors and timings
 [-tol {10|20|30|40} ]
   10 20 30 or 40 seconds tollerance for
   identifying relevant timesteps in log
 [-sen <sensor id number> ] if included
   restricts reporting to this sensor id
   (only for older BuildAX hardware)
 -nodbt exclude temperature
 -norh  exclude relative humidity
 -nolux exclude Lux
 -nopir exclude PIR
 -nosw exclude switch count
 -ex XXXXXXXX exclude sensor XXXXXXXX from report
 [-file <BuildAX log (csv) file name>]
 [-help  this message
 
The input file is assumed to be a csv file in the
following format:
 . . .
2015/01/22,12:56:34,42E77A24,-102,1,118,20,3103,51.23,167,30,0,43162,1
2015/01/22,12:56:38,42D5E85D,-56,1,115,20,3135,34.74,223,7,0,54508,1
2015/01/22,12:56:52,42A45156,-93,1,187,20,3124,54.57,214,21,0,49279,1
2015/01/22,13:00:00,42CAD40D,-74,1,74,20,3110,34.94,230,357,0,38061,1
2015/01/22,13:01:26,42D5E85D,-56,1,116,20,3136,34.90,223,6,0,61566,1
2015/01/22,13:02:00,42A45156,-93,1,188,20,3124,56.00,216,33,0,52487,1
2015/01/22,13:04:52,42CAD40D,-76,1,75,20,3110,35.03,230,221,0,44499,1
2015/01/22,13:06:14,42D5E85D,-70,1,117,20,3135,36.45,227,10,0,3241,1
2015/01/22,13:07:04,42E77A24,-104,1,120,20,3103,42.55,162,34,0,337,1
 . . .

Such files are produced via the bax2csv application from the BIN files
generated by the BuildAX LRS. One intial task after converting LRS
BIN files is to see how often sensors have broadcast information.
The -act L option scans the file and generates a brief report. Example:

  ./log2csv -act L -file houses.csv
 the input file is: houses.csv
command line action is L
 processing...houses.csv                                                                                                                                      
 the file format is            3  L               
 
 In houses.csv error reading (log line) EOF sensed.
 Rewinding the file after scan for sensors.
list:     1    2    3    4    5    0    0    0    0    0    0
 42A45156   6.96641350            1275   472.076965    
 42D5E85D   6.98283577            2079   290.195770    
 42E77A24   6.92304230             658   909.043884    
 42CAD40D   6.97874832            2055   293.413086    

The columns have the following meanings:
 sensor ID  ignore    number of instances ignore
 42A25188   1.95996475             818   207.018280

So both 42CAD40D and 42D5E85D have many more entries than
42A45156 or 42E77A24
   
The application log2csv takes a file.csv and generates
a file.text in the form:
BuildAX summary from LRS
number of sensors  4
include,degC
include,Lux
include,RH
include,PIR
include,SW
sensor list 42A45156,42CAD40D,42D5E85D,42E77A24
JulianTime,yyyy-mm-dd,hh:mm,42A45156_degC,42A45156_Lux,42A45156_RH,42A45156_PIR,42A45156_SW,42CAD40D_degC,42CAD40D_Lux,42CAD40D_RH,42CAD40D_PIR,42CAD40D_SW,42D5E85D_degC,
42D5E85D_Lux,42D5E85D_RH,42D5E85D_PIR,42D5E85D_SW,42E77A24_degC,42E77A24_Lux,42E77A24_RH,42E77A24_PIR,42E77A24_SW,
 22.461805,2015/01/22,11:05,18.700,3.0000,46.860,41676.,1.0000,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
 22.468750,2015/01/22,11:15,18.700,3.0000,46.890,45301.,1.0000,20.700,65.000,37.380,22982.,1.0000,20.000,7.0000,38.560,26584.,1.0000,16.800,6.0000,50.360,12585.,1.0000
 22.472223,2015/01/22,11:20,18.600,4.0000,49.140,48988.,1.0000,21.000,68.000,37.240,30294.,1.0000,20.100,7.0000,38.240,34474.,1.0000,16.800,7.0000,50.810,23798.,1.0000
 22.475695,2015/01/22,11:25,18.500,5.0000,51.810,52601.,1.0000,21.200,65.000,37.010,37230.,1.0000,20.300,8.0000,38.000,42637.,1.0000,16.800,6.0000,50.450,34825.,1.0000
 22.479168,2015/01/22,11:30,18.600,4.0000,54.280,56176.,1.0000,21.300,63.000,36.940,44079.,1.0000,20.500,7.0000,36.970,50381.,1.0000,16.700,6.0000,50.440,46369.,1.0000
 22.482639,2015/01/22,11:35,18.700,7.0000,54.440,59914.,1.0000,21.500,57.000,36.430,51085.,1.0000,20.700,8.0000,36.540,58073.,1.0000,16.700,5.0000,50.190,57879.,1.0000
 22.486113,2015/01/22,11:40,18.700,7.0000,56.460,63589.,1.0000,21.600,89.000,36.300,64667.,1.0000,20.700,9.0000,36.410,64890.,1.0000,16.600,7.0000,50.030,3691.0,1.0000
 22.489584,2015/01/22,11:45,18.900,21.000,58.770,1567.0,1.0000,21.600,89.000,36.300,64667.,1.0000,21.000,12.000,36.100,7231.0,1.0000,16.500,8.0000,49.970,15265.,1.0000
 22.493055,2015/01/22,11:50,19.200,24.000,61.110,5242.0,1.0000,21.800,159.00,36.170,5803.0,1.0000,21.000,11.000,35.870,15032.,1.0000,16.500,9.0000,49.930,26725.,1.0000
 . . .
 
If you want to ignore certain types of data e.g. PIR and Switch events then modify
the command line:

  ./log2csv -act 2 -nopir -nosw houses.csv

which creates:
BuildAX summary from LRS
number of sensors  4
include,degC
include,Lux
include,RH
ignore,PIR
ignore,SW
sensor list 42A45156,42CAD40D,42D5E85D,42E77A24
JulianTime,yyyy-mm-dd,hh:mm,42A45156_degC,42A45156_Lux,42A45156_RH,42CAD40D_degC,42CAD40D_Lux,42CAD40D_RH,42D5E85D_degC,42D5E85D_Lux,42D5E85D_RH,42E77A24_degC,42E77A24_Lux,42E77A24_RH,
 22.461805,2015/01/22,11:05,18.700,3.0000,46.860,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
 22.468750,2015/01/22,11:15,18.700,3.0000,46.890,20.700,65.000,37.380,20.000,7.0000,38.560,16.800,6.0000,50.360
 22.472223,2015/01/22,11:20,18.600,4.0000,49.140,21.000,68.000,37.240,20.100,7.0000,38.240,16.800,7.0000,50.810
 22.475695,2015/01/22,11:25,18.500,5.0000,51.810,21.200,65.000,37.010,20.300,8.0000,38.000,16.800,6.0000,50.450
 22.479168,2015/01/22,11:30,18.600,4.0000,54.280,21.300,63.000,36.940,20.500,7.0000,36.970,16.700,6.0000,50.440
 22.482639,2015/01/22,11:35,18.700,7.0000,54.440,21.500,57.000,36.430,20.700,8.0000,36.540,16.700,5.0000,50.190
 22.486113,2015/01/22,11:40,18.700,7.0000,56.460,21.600,89.000,36.300,20.700,9.0000,36.410,16.600,7.0000,50.030
 22.489584,2015/01/22,11:45,18.900,21.000,58.770,21.600,89.000,36.300,21.000,12.000,36.100,16.500,8.0000,49.970

If you want to exclue BuildAX ENV sensors then the command line
takes the form:
./log2csv -act 2 -ex 42A45156 -ex 42CAD40D houses.csv

which produces:

BuildAX summary from LRS
number of sensors  2
include,degC
include,Lux
include,RH
include,PIR
include,SW
sensor list 42D5E85D,42E77A24
JulianTime,yyyy-mm-dd,hh:mm,42D5E85D_degC,42D5E85D_Lux,42D5E85D_RH,42D5E85D_PIR,42D5E85D_SW,42E77A24_degC,42E77A24_Lux,42E77A24_RH,42E77A24_PIR,42E77A24_SW,
 22.465279,2015/01/22,11:10,19.700,7.0000,38.280,18590.,1.0000,0.00,0.00,0.00,0.00,0.00
 22.468750,2015/01/22,11:15,20.000,7.0000,38.560,26584.,1.0000,16.800,6.0000,50.360,12585.,1.0000
 22.472223,2015/01/22,11:20,20.100,7.0000,38.240,34474.,1.0000,16.800,7.0000,50.810,23798.,1.0000
 22.475695,2015/01/22,11:25,20.300,8.0000,38.000,42637.,1.0000,16.800,6.0000,50.450,34825.,1.0000
 22.479168,2015/01/22,11:30,20.500,7.0000,36.970,50381.,1.0000,16.700,6.0000,50.440,46369.,1.0000
 22.482639,2015/01/22,11:35,20.700,8.0000,36.540,58073.,1.0000,16.700,5.0000,50.190,57879.,1.0000
 22.486113,2015/01/22,11:40,20.700,9.0000,36.410,64890.,1.0000,16.500,8.0000,49.970,15265.,1.0000
 22.489584,2015/01/22,11:45,21.000,12.000,36.100,7231.0,1.0000,16.500,9.0000,49.930,26725.,1.0000
 22.493055,2015/01/22,11:50,21.000,11.000,35.870,15032.,1.0000,16.400,8.0000,50.320,38271.,1.0000
 22.496529,2015/01/22,11:55,21.100,10.000,35.760,22896.,1.0000,16.400,8.0000,50.270,49679.,1.0000

